import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.Set;

public class RedisDemoSet {
    public static void  test1(Jedis jedis) {
        System.out.println("sadd smembers");
        jedis.flushAll();

        jedis.sadd("key", "111", "222", "333");
        Set<String> values = jedis.smembers("key");
        System.out.println(values);
    }

    public static void  test2(Jedis jedis) {
        System.out.println("sismember");
        jedis.flushAll();

        jedis.sadd("key", "111", "222", "333");
        boolean res = jedis.sismember("key", "1");
        System.out.println(res);
    }

    public static void  test3(Jedis jedis) {
        System.out.println("scard");
        jedis.flushAll();

        jedis.sadd("key", "111", "222", "333");
        long res = jedis.scard("key");
        System.out.println(res);
    }

    public static void  test4(Jedis jedis) {
        System.out.println("spop");
        jedis.flushAll();

        jedis.sadd("key", "111", "222", "333", "444", "555");
        String val = jedis.spop("key");
        String val2 = jedis.spop("key");
        String val3 = jedis.spop("key");
        System.out.println(val);
        System.out.println(val2);
        System.out.println(val3);
    }

    public static void  test5(Jedis jedis) {
        System.out.println("sinter");
        jedis.flushAll();

        jedis.sadd("key", "111", "222", "333", "444", "555");
        jedis.sadd("key2", "000", "111", "222", "333");
        Set<String> sinter = jedis.sinter("key", "key2");
        System.out.println(sinter);
    }

    public static void  test6(Jedis jedis) {
        System.out.println("sinterstore");
        jedis.flushAll();

        jedis.sadd("key", "111", "222", "333", "444", "555");
        jedis.sadd("key2", "000", "111", "222", "333", "444");
        long res = jedis.sinterstore("dkey", "key", "key2");

        Set<String> values = jedis.smembers("dkey");
        System.out.println(res);
        System.out.println(values);
    }

    public static void main(String[] args) {
        JedisPool jedisPool = new JedisPool("tcp://127.0.0.1:8888");
        try (Jedis jedis = jedisPool.getResource()){
            test6(jedis);
        }
    }
}
